//
//  UIViewController+Addition.m
//  CrossScreenVOD
//
//  Created by Dongfuming on 2017/12/25.
//  Copyright © 2017年 china-avs. All rights reserved.
//

#import "UIViewController+Addition.h"
#import "UIView+Addtion.h"

@implementation UIViewController (Addition)

- (void)showHUD
{
    [self.view showHUD];
}

- (void)hideHUD
{
     [self.view hideHUD];
}

- (void)handleRequestFailure:(NSError *)error
{
    [self.view makeToastWithRequestFailure:error];
}

- (void)showInfo:(NSString *)message
{
    [self.view showInfo:message];
}

- (void)showSuccess:(NSString *)message
{
    [self.view showSuccess:message];
}

- (void)showError:(NSString *)message
{
    [self.view showError:message];
}

+ (UIViewController *)currentViewController
{
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    UIViewController *topViewController = [window rootViewController];
    while (true) {
        if (topViewController.presentedViewController) {
            topViewController = topViewController.presentedViewController;
        } else if ([topViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)topViewController topViewController]) {
            topViewController = [(UINavigationController *)topViewController topViewController];
        } else if ([topViewController isKindOfClass:[UITabBarController class]]) {
            UITabBarController *tab = (UITabBarController *)topViewController;
            topViewController = tab.selectedViewController;
        } else {
            break;
        }
    }
    return topViewController;
}

@end
